//
//  HQTimeView.m
//  NewMusic
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "HQTimeView.h"

@interface HQTimeView ()<UIPickerViewDataSource, UIPickerViewDelegate>
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UIPickerView *pickView;
@property (nonatomic, retain) NSArray *arr;
@property (nonatomic, retain) NSString *timeStr;
@end

@implementation HQTimeView

- (void)dealloc
{
    [_label release];
    [_pickView release];
    [_arr release];
    [_timeStr release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView
{
    self.timeStr = @"10分钟";    
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 260)];
    self.backView.backgroundColor = [UIColor colorWithRed:50 / 255.0 green:50 / 255.0 blue:50 / 255.0 alpha:1.0];
    self.backView.layer.cornerRadius = 6;
    [self addSubview:self.backView];
    [_backView release];
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 200, 20)];
    self.label.text = @"音乐将在10分钟后关闭";
    self.label.font = [UIFont systemFontOfSize:19];
    self.label.textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0  blue:200 / 255.0  alpha:1.0];
    self.label.textAlignment = NSTextAlignmentCenter;
    [self.backView addSubview:self.label];
    [_label release];
    
    self.pickView = [[UIPickerView alloc] initWithFrame:CGRectMake(50, 50, 200, 160)];
    self.pickView.backgroundColor = [UIColor whiteColor];
    self.pickView.delegate = self;
    self.pickView.dataSource = self;
    [self.backView addSubview:self.pickView];
    self.pickView.layer.cornerRadius = 8;
    [_pickView release];
    [self.pickView reloadAllComponents];
    
    self.arr = [NSArray arrayWithObjects:@"10分钟", @"20分钟", @"30分钟", @"40分钟", @"50分钟", @"60分钟", nil];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [self addGestureRecognizer:tap];
    [tap release];
}
- (void)tapAction
{
    [self.delegate removeTimeView:[[self.timeStr substringToIndex:2] integerValue]];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.arr.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.arr[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.timeStr = self.arr[row];
    self.label.text = [NSString stringWithFormat:@"音乐将在%@后关闭", self.arr[row]];
}

@end
